import mysql.connector
from enum import Enum


class ConfigCode(Enum):
    SAVE_TIME = "ai-vision-res-save-time"
    MSG_PUSH = "ai-vision-msg-push"
    FREQUENCY = "ai-vision-frequency"


def get_val_by_code(configCode):
    mydb = mysql.connector.connect(
        host="com-server.rwlb.rds.aliyuncs.com",
        user="opendb",
        password="Fmhb2022!@#",
        database="ntd_server"
    )
    mycursor = mydb.cursor()
    sql = "SELECT val FROM common_config WHERE code = %s"
    na = (configCode.value,)
    mycursor.execute(sql, na)
    myresult = mycursor.fetchone()
    return myresult[0]
